home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / adatutor / class.txt < prev    next >
Text File  |  1996-01-30  |  42KB  |  1,010 lines

  1. The following pages contain listings of three reusable component
  2. specifications in Ada from the CSPARTS collection.  These specifications
  3. are:
  4.  
  5.     CONSOLE   -- an abstract state machine which provides an
  6.             interface to the user's console
  7.  
  8.     DLIST     -- a class definition which defines a doubly-linked
  9.             list class of objects
  10.  
  11.     TOD       -- a collection of utility routines for converting
  12.             between various time of day representations
  13.             to Ada's CALENDAR.TIME format
  14.  
  15.  
  16.  
  17.  
  18. -- *********************************************************
  19. -- *                                                       *
  20. -- *  Console                                              *  SPEC
  21. -- *                                                       *
  22. -- *********************************************************
  23. package Console is
  24. --| Purpose
  25. --| Console provides a set of I/O and screen control commands
  26. --| for either IBM PC computers employing the ANSI.SYS device
  27. --| driver or the VT100-compatible family of terminals.  By using
  28. --| this package, a programmer may manipulate the terminal screen
  29. --| regardless if it is an IBM PC with ANSI.SYS or a VT100 terminal.
  30. --|
  31. --| The console object runs in one of three modes:
  32. --|   TTY        All screen-oriented commands are disabled
  33. --|   VT100      All screen-oriented commands except display
  34. --|              color control (foreground and background)
  35. --|              are enabled
  36. --|   ANSI       All screen-oriented commands are enabled
  37. --| The default mode is TTY, and the mode of the console object
  38. --| can be changed at any time by calling the Set_Terminal
  39. --| routine.
  40. --|
  41. --| The output to the console object can be enabled or disabled
  42. --| by using the Enable_Output and Disable_Output routines.
  43. --| The Push and Pop routines can be used to preserve the current
  44. --| state of the console and restore the console to the previous
  45. --| state.
  46. --|
  47. --| Initialization Exceptions (none)
  48. --| Notes (none)
  49. --|
  50. --| Modifications
  51. --| 3/8/91  Richard Conn  Initial Release
  52.  
  53.   Max_Number_of_States : constant NATURAL := 10;
  54.   -- number of enable/disable states to the console; also,
  55.   -- number of Push calls before a State_Overflow exception
  56.  
  57.   type TERMINAL_KIND is (TTY,   -- no screen-oriented commands
  58.                          ANSI,  -- colors supported
  59.                          VT100  -- no colors
  60.                         );
  61.  
  62.   type ROW_NUMBER is new INTEGER range 1..24;
  63.   type COLUMN_NUMBER is new INTEGER range 1..80;
  64.  
  65.   type RENDITION is
  66.       (ALL_ATTRIBUTES_OFF,      -- ANSI.SYS or VT100
  67.        HIGH_INTENSITY,
  68.        BLINKING,
  69.        REVERSE_VIDEO,
  70.        FOREGROUND_BLACK,        -- ANSI.SYS only
  71.        FOREGROUND_RED,
  72.        FOREGROUND_GREEN,
  73.        FOREGROUND_YELLOW,
  74.        FOREGROUND_BLUE,
  75.        FOREGROUND_MAGENTA,
  76.        FOREGROUND_CYAN,
  77.        FOREGROUND_WHITE,
  78.        BACKGROUND_BLACK,
  79.        BACKGROUND_RED,
  80.        BACKGROUND_GREEN,
  81.        BACKGROUND_YELLOW,
  82.        BACKGROUND_BLUE,
  83.        BACKGROUND_MAGENTA,
  84.        BACKGROUND_CYAN,
  85.        BACKGROUND_WHITE);
  86.   for RENDITION'Size use INTEGER'Size;
  87.   for RENDITION use
  88.       (ALL_ATTRIBUTES_OFF      => 0,  -- ANSI.SYS or VT100
  89.        HIGH_INTENSITY          => 1,
  90.        BLINKING                => 5,
  91.        REVERSE_VIDEO           => 7,
  92.        FOREGROUND_BLACK        => 30, -- ANSI.SYS only
  93.        FOREGROUND_RED          => 31,
  94.        FOREGROUND_GREEN        => 32,
  95.        FOREGROUND_YELLOW       => 33,
  96.        FOREGROUND_BLUE         => 34,
  97.        FOREGROUND_MAGENTA      => 35,
  98.        FOREGROUND_CYAN         => 36,
  99.        FOREGROUND_WHITE        => 37,
  100.        BACKGROUND_BLACK        => 40,
  101.        BACKGROUND_RED          => 41,
  102.        BACKGROUND_GREEN        => 42,
  103.        BACKGROUND_YELLOW       => 43,
  104.        BACKGROUND_BLUE         => 44,
  105.        BACKGROUND_MAGENTA      => 45,
  106.        BACKGROUND_CYAN         => 46,
  107.        BACKGROUND_WHITE        => 47);
  108.  
  109.   type OVERFLOW_ACTION is  -- used for a Put(STRING)
  110.     (TRUNCATE_HEAD,          -- ABC becomes "BC"
  111.      TRUNCATE_TAIL,          -- ABC becomes "AB"
  112.      FILL_WITH_OVERFLOW_CHAR -- ABC becomes "**"
  113.     );
  114.  
  115.   type NUMERIC_OVERFLOW_ACTION is -- used for a Put(INTEGER)
  116.     (FILL_WITH_OVERFLOW_CHAR,  -- 123 becomes "**"
  117.      OUTPUT_FULL_NUMBER        -- 123 becomes "123"
  118.     );
  119.  
  120.   type JUSTIFICATION   is  -- used for a Put(STRING)
  121.     (LEFT_JUSTIFIED,         -- ABC becomes "ABC "
  122.      RIGHT_JUSTIFIED         -- ABC becomes " ABC"
  123.     );
  124.  
  125.   INPUT_ERROR : exception;  -- raised on invalid input
  126.   STATE_OVERFLOW : exception;
  127.       -- raised if the Max_Number_of_States is exceeded
  128.   STATE_UNDERFLOW : exception;
  129.       -- raised if too many Pop routine calls are made
  130.  
  131.   -- ..............................................................
  132.   -- .                                                            .
  133.   -- .  Console.Set_Terminal                                      .  SPEC
  134.   -- .                                                            .
  135.   -- ..............................................................
  136.   procedure Set_Terminal (New_Setting : in TERMINAL_KIND := TTY);
  137.   --| Purpose
  138.   --| Define the kind of user's terminal.  If this routine is not
  139.   --| called, TTY is assumed.
  140.   --|
  141.   --| Exceptions (none)
  142.   --| Notes (none)
  143.  
  144.   -- ..............................................................
  145.   -- .                                                            .
  146.   -- .  Console.Enable_Output                                     .  SPEC
  147.   -- .                                                            .
  148.   -- ..............................................................
  149.   procedure Enable_Output;
  150.   --| Purpose
  151.   --| Enable the output routines of the console object (affects current
  152.   --| state only).  These routines include Position_Cursor, Erase_Display,
  153.   --| Erase_Line, Set_Rendition, all the Put and Put_Line routines, and
  154.   --| New_Line.
  155.   --|
  156.   --| Exceptions (none)
  157.   --| Notes (none)
  158.  
  159.   -- ..............................................................
  160.   -- .                                                            .
  161.   -- .  Console.Disable_Output                                    .  SPEC
  162.   -- .                                                            .
  163.   -- ..............................................................
  164.   procedure Disable_Output;
  165.   --| Purpose
  166.   --| Disable the output routines of the console object (affects current
  167.   --| state only).  These routines include Position_Cursor, Erase_Display,
  168.   --| Erase_Line, Set_Rendition, all the Put and Put_Line routines, and
  169.   --| New_Line.
  170.   --|
  171.   --| Exceptions (none)
  172.   --| Notes (none)
  173.  
  174.   -- ..............................................................
  175.   -- .                                                            .
  176.   -- .  Console.Push                                              .  SPEC
  177.   -- .                                                            .
  178.   -- ..............................................................
  179.   procedure Push;
  180.   --| Purpose
  181.   --| Increment to the next state (environment) of the console object.
  182.   --| All states are initialized to be enabled.  This routine permits,
  183.   --| for example, a console to be turned off for silent running and
  184.   --| then temporarily turned on for an error message display.  The
  185.   --| console object stays in this new state, which may be altered by
  186.   --| the Enable_Output and Disable_Output routines, until a Pop is
  187.   --| executed.
  188.   --|
  189.   --| Exceptions
  190.   --|   STATE_OVERFLOW -- raised if Max_Number_of_States is exceeded
  191.   --| Notes (none)
  192.  
  193.   -- ..............................................................
  194.   -- .                                                            .
  195.   -- .  Console.Pop                                               .  SPEC
  196.   -- .                                                            .
  197.   -- ..............................................................
  198.   procedure Pop;
  199.   --| Purpose
  200.   --| Decrement to the previous state (environment) of the console object.
  201.   --| All states are initialized to be enabled.  See the Push routine
  202.   --| for more details.
  203.   --|
  204.   --| Exceptions
  205.   --|   STATE_UNDERFLOW -- raised if current state tries to drop below 0
  206.   --| Notes (none)
  207.  
  208.   -- ..............................................................
  209.   -- .                                                            .
  210.   -- .  Console.Position_Cursor                                   .  SPEC
  211.   -- .                                                            .
  212.   -- ..............................................................
  213.   procedure Position_Cursor (Row    : in ROW_NUMBER;
  214.                              Column : in COLUMN_NUMBER);
  215.   --| Purpose
  216.   --| Position the cursor to the indicated Row and Column.  Row 1,
  217.   --| Column 1 is the upper left corner of the screen.
  218.   --|
  219.   --| Exceptions (none)
  220.   --| Notes (none)
  221.  
  222.   -- ..............................................................
  223.   -- .                                                            .
  224.   -- .  Console.Erase_Display                                     .  SPEC
  225.   -- .                                                            .
  226.   -- ..............................................................
  227.   procedure Erase_Display;
  228.   --| Purpose
  229.   --| Erase the entire display and place the cursor at the home position.
  230.   --|
  231.   --| Exceptions (none)
  232.   --| Notes (none)
  233.  
  234.   -- ..............................................................
  235.   -- .                                                            .
  236.   -- .  Console.Erase_Line                                        .  SPEC
  237.   -- .                                                            .
  238.   -- ..............................................................
  239.   procedure Erase_Line;
  240.   --| Purpose
  241.   --| Erase from the cursor to the end of the line.
  242.   --|
  243.   --| Exceptions (none)
  244.   --| Notes (none)
  245.  
  246.   -- ..............................................................
  247.   -- .                                                            .
  248.   -- .  Console.Set_Rendition                                     .  SPEC
  249.   -- .                                                            .
  250.   -- ..............................................................
  251.   procedure Set_Rendition (New_Setting : in RENDITION);
  252.   --| Purpose
  253.   --| Add the indicated New_Setting to the current graphics display
  254.   --| rendition (default is ALL_ATTRIBUTES_OFF).  Calls to this procedure
  255.   --| are cumulative until all attributes are turned off.
  256.   --|
  257.   --| Exceptions (none)
  258.   --|
  259.   --| Notes
  260.   --|   Color selections are ignored on a VT100 compatible terminal.
  261.  
  262.   -- ..............................................................
  263.   -- .                                                            .
  264.   -- .  Console.Put                                               .  SPEC
  265.   -- .                                                            .
  266.   -- ..............................................................
  267.   procedure Put (Item : in CHARACTER);
  268.   procedure Put (Item : in STRING);
  269.   --| Purpose
  270.   --| Output a character or a string to the console.
  271.   --|
  272.   --| Exceptions (none)
  273.   --| Notes (none)
  274.  
  275.   -- ..............................................................
  276.   -- .                                                            .
  277.   -- .  Console.Put                                               .  SPEC
  278.   -- .                                                            .
  279.   -- ..............................................................
  280.   procedure Put
  281.     ( Item           : in STRING;
  282.       Field_Width    : in NATURAL;
  283.       On_Overflow    : in OVERFLOW_ACTION := TRUNCATE_TAIL;
  284.       On_Underflow   : in JUSTIFICATION   := LEFT_JUSTIFIED;
  285.       Fill_Char      : in CHARACTER       := ' ';
  286.       Overflow_Char  : in CHARACTER       := '*' );
  287.   --| Purpose
  288.   --| Output a string to the console in a field of a given
  289.   --| Field_Width.
  290.   --|     If Item is shorter than Field_Width,
  291.   --| the On_Underflow flag takes effect, justifying Item
  292.   --| in the field as indicated using the Fill_Char.
  293.   --|     If Item is longer than Field_Width, the On_Overflow
  294.   --| flag takes effect, either truncating Item on the left or
  295.   --| right or filling the field with the Overflow_Char.
  296.   --|
  297.   --| Exceptions (none)
  298.   --| Notes (none)
  299.  
  300.   -- ..............................................................
  301.   -- .                                                            .
  302.   -- .  Console.Put                                               .  SPEC
  303.   -- .                                                            .
  304.   -- ..............................................................
  305.   procedure Put (Item          : in INTEGER;
  306.                  Width         : in NATURAL;
  307.                  On_Overflow   : in NUMERIC_OVERFLOW_ACTION
  308.                                    := FILL_WITH_OVERFLOW_CHAR;
  309.                  Overflow_Char : in CHARACTER := '*');
  310.   --| Purpose
  311.   --| Output an integer to the console.  It will be placed in a
  312.   --| field that is Width characters long.  Width of 0 fits the
  313.   --| INTEGER exactly.  If the resulting sequence of characters
  314.   --| has fewer than Width characters, then leading spaces are
  315.   --| first output to make up the difference.  If the resulting
  316.   --| sequence of characters has more than Width characters,
  317.   --| then the On_Overflow flag takes effect.
  318.   --|
  319.   --| Exceptions (none)
  320.   --| Notes (none)
  321.  
  322.   -- ..............................................................
  323.   -- .                                                            .
  324.   -- .  Console.Put                                               .  SPEC
  325.   -- .                                                            .
  326.   -- ..............................................................
  327.   procedure Put (Item          : in FLOAT;
  328.                  Fore          : in NATURAL;
  329.                  Aft           : in NATURAL;
  330.                  On_Overflow   : in NUMERIC_OVERFLOW_ACTION
  331.                                    := FILL_WITH_OVERFLOW_CHAR;
  332.                  Overflow_Char : in CHARACTER := '*');
  333.   --| Purpose
  334.   --| Output a floating point number to the console.  Fore is the
  335.   --| number of characters to be displayed before the decimal point,
  336.   --| and Aft is the number of characters to be displayed after the
  337.   --| decimal point.  Item's value appears as follows:
  338.   --|
  339.   --|        Fore Aft      fields
  340.   --|        ---- ---      (Fore=4, Aft=3)
  341.   --|        nnnn.nnn      if Item is positive
  342.   --|        -nnn.nnn      if Item is negative
  343.   --|        ********      if overflow with defaults
  344.   --|
  345.   --|     If Item is negative, a leading minus sign, which counts as
  346.   --| one of the characters in the Fore field, is output.
  347.   --|     If -1.0 < Item < 1.0, then -0 or 0 is output in the Fore
  348.   --| field.
  349.   --|     If the number of digits required to display Item in the Fore
  350.   --| field exceeds the value of Fore (i.e., is too big), the
  351.   --| On_Overflow flag takes effect, either overriding Fore or filling
  352.   --| the field with the Overflow_Char.
  353.   --|
  354.   --| Exceptions (none)
  355.   --| Notes (none)
  356.  
  357.   -- ..............................................................
  358.   -- .                                                            .
  359.   -- .  Console.Put                                               .  SPEC
  360.   -- .                                                            .
  361.   -- ..............................................................
  362.   procedure Put (Item : in FLOAT;
  363.                  Fore : in NATURAL := 2;
  364.                  Aft  : in NATURAL := 2;
  365.                  Exp  : in NATURAL := 3);
  366.   --| Purpose
  367.   --| Output a floating point number in scientific notation
  368.   --| to the console.  Fore is the number of characters to be
  369.   --| displayed before the decimal point (only one digit and
  370.   --| a sign are displayed, so rest of Fore characters are
  371.   --| leading spaces), Aft is the number of characters to be
  372.   --| displayed after the decimal point, and Exp is the number
  373.   --| of characters in the exponent.  Item's value appears as:
  374.   --|
  375.   --|          -- ---- ---      (Fore=2, Aft=4, Exp=3)
  376.   --|           n.nnnnE+nn      if Item is positive
  377.   --|          -n.nnnnE+nn      if Item is negative
  378.   --|
  379.   --|     The Fore field will always contain a single digit with
  380.   --| an optional minus sign.  If Fore > 2, leading spaces are
  381.   --| prefixed to the output.  Hence, Put(-123.0, 4, 2, 3) outputs
  382.   --| "  -1.23E+02".
  383.   --|     Exp is the size of the field for the number after the "E".
  384.   --| This field always includes a leading sign (see -123.0 example
  385.   --| above).
  386.   --|
  387.   --| Exceptions (none)
  388.   --| Notes (none)
  389.  
  390.   -- ..............................................................
  391.   -- .                                                            .
  392.   -- .  Console.Put_Line                                          .  SPEC
  393.   -- .                                                            .
  394.   -- ..............................................................
  395.   procedure Put_Line (Item : in STRING);
  396.   --| Purpose
  397.   --| Output a string followed by a new line to the console.
  398.   --|
  399.   --| Exceptions (none)
  400.   --| Notes (none)
  401.  
  402.   -- ..............................................................
  403.   -- .                                                            .
  404.   -- .  Console.New_Line                                          .  SPEC
  405.   -- .                                                            .
  406.   -- ..............................................................
  407.   procedure New_Line;
  408.   --| Purpose
  409.   --| Output a new line to the console.
  410.   --|
  411.   --| Exceptions (none)
  412.   --| Notes (none)
  413.  
  414.   -- ..............................................................
  415.   -- .                                                            .
  416.   -- .  Console.Get                                               .  SPEC
  417.   -- .                                                            .
  418.   -- ..............................................................
  419.   procedure Get
  420.     ( Item          : out CHARACTER);
  421.   procedure Get
  422.     ( Item          : out INTEGER);
  423.   procedure Get
  424.     ( Item          : out FLOAT);
  425.   --| Purpose
  426.   --| Get views the Console input as a stream and
  427.   --| returns the next Item of the appropriate type
  428.   --| from it.
  429.   --|
  430.   --| Exceptions
  431.   --|   Input_Error  raised if the next item
  432.   --|                in the stream is not of the
  433.   --|                correct type when translated
  434.   --|                from the characters or if the
  435.   --|                translation process encounters
  436.   --|                an error condition
  437.   --|
  438.   --| Notes
  439.   --|   If the Item is of type INTEGER or FLOAT, Get
  440.   --| skips over whitespace characters (blank, tab, new
  441.   --| line) first and then starts translating at the
  442.   --| first non-white character encountered.
  443.   --|   If the Item is of type CHARACTER, Get returns
  444.   --| the next character, whitespace or not.
  445.  
  446.   -- ..............................................................
  447.   -- .                                                            .
  448.   -- .  Console.Get_Line                                          .  SPEC
  449.   -- .                                                            .
  450.   -- ..............................................................
  451.   procedure Get_Line
  452.     ( Item           : out STRING;
  453.       Last           : out NATURAL );
  454.   --| Purpose
  455.   --| Get_Line reads a line from the console.
  456.   --|
  457.   --| Exceptions (none)
  458.   --| Notes (none)
  459.  
  460. end Console;
  461.  
  462.  
  463.  
  464. -- **********************************************************
  465. -- *                                                        *
  466. -- *  DOUBLY_LINKED_LIST                                    *  SPEC
  467. -- *                                                        *
  468. -- **********************************************************
  469. generic
  470.    type ELEMENT_OBJECT is private;
  471. package Doubly_Linked_List is
  472. --| Purpose   
  473. --| DOUBLY_LINKED_LIST manipulates the abstract data type
  474. --| LIST_ID, which is a linked list of objects.
  475. --| DOUBLE_LIST provides routines to add objects to,
  476. --| delete objects from, and extract objects from
  477. --| the list.  DOUBLE_LIST also allows the user to
  478. --| move about through the list and manipulate the
  479. --| list in various ways.
  480. --|
  481. --| Initialization Exceptions (none)
  482. --|
  483. --| Notes
  484. --| The number of list elements is restricted to 
  485. --| INTEGER'LAST and the amount of memory or virtual
  486. --| memory in the computer system.
  487. --|
  488. --| Modifications
  489. --| Author: Richard Conn
  490.    
  491. -- Types
  492.   type ELEMENT_POSITION is new INTEGER range 0 .. INTEGER'LAST;
  493.   type LIST_ID is limited private;
  494.    
  495. -- Exceptions
  496.   ADVANCE_PAST_END_OF_LIST          : exception;
  497.   BACKUP_BEFORE_BEGINNING_OF_LIST   : exception;
  498.   DYNAMIC_MEMORY_ALLOCATION_PROBLEM : exception;
  499.   LIST_IS_EMPTY                     : exception;
  500.   INVALID_INDEX                     : exception;
  501.   UNEXPECTED_ERROR                  : exception;  -- raised anytime
  502.    
  503.   -- ........................................................
  504.   -- .                                                      .
  505.   -- .  DOUBLY_LINKED_LIST.INITIALIZE                       .  SPEC
  506.   -- .                                                      .
  507.   -- ........................................................
  508.   procedure Initialize (ID : in out LIST_ID);
  509.   --| Purpose
  510.   --| Initialize the list to empty (the list is empty when
  511.   --| first used); if the list contained any elements, they
  512.   --| are deleted.
  513.   --|
  514.   --| Exceptions (none)
  515.   --| Notes (none)
  516.    
  517.   -- ........................................................
  518.   -- .                                                      .
  519.   -- .  DOUBLY_LINKED_LIST.FIRST_ELEMENT                    .  SPEC
  520.   -- .                                                      .
  521.   -- ........................................................
  522.   function First_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  523.   --| Purpose
  524.   --| Return the first element of the list.
  525.   --|
  526.   --| Exceptions
  527.   --|   LIST_IS_EMPTY
  528.   --|
  529.   --| Notes (none)
  530.  
  531.   -- ........................................................
  532.   -- .                                                      .
  533.   -- .  DOUBLY_LINKED_LIST.LAST_ELEMENT                     .  SPEC
  534.   -- .                                                      .
  535.   -- ........................................................
  536.   function Last_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  537.   --| Purpose
  538.   --| Return the last element of the list.
  539.   --|
  540.   --| Exceptions
  541.   --|   LIST_IS_EMPTY
  542.   --|
  543.   --| Notes (none)
  544.    
  545.   -- ........................................................
  546.   -- .                                                      .
  547.   -- .  DOUBLY_LINKED_LIST.CURRENT_ELEMENT                  .  SPEC
  548.   -- .                                                      .
  549.   -- ........................................................
  550.   function Current_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  551.   --| Purpose
  552.   --| Return the current element of the list.
  553.   --|
  554.   --| Exceptions
  555.   --|   LIST_IS_EMPTY
  556.   --|
  557.   --| Notes (none)
  558.    
  559.   -- ........................................................
  560.   -- .                                                      .
  561.   -- .  DOUBLY_LINKED_LIST.GOTO_FIRST                       .  SPEC
  562.   -- .                                                      .
  563.   -- ........................................................
  564.   procedure Goto_First (ID : in out LIST_ID);
  565.   --| Purpose
  566.   --| Set the current element of the list to be the first
  567.   --| element.
  568.   --|
  569.   --| Exceptions
  570.   --|   LIST_IS_EMPTY
  571.   --|
  572.   --| Notes (none)
  573.    
  574.   -- ........................................................
  575.   -- .                                                      .
  576.   -- .  DOUBLY_LINKED_LIST.GOTO_LAST                        .  SPEC
  577.   -- .                                                      .
  578.   -- ........................................................
  579.   procedure Goto_Last (ID : in out LIST_ID);
  580.   --| Purpose
  581.   --| Set the current element of the list to be the last
  582.   --| element.
  583.   --|
  584.   --| Exceptions
  585.   --|   LIST_IS_EMPTY
  586.   --|
  587.   --| Notes (none)
  588.    
  589.   -- ........................................................
  590.   -- .                                                      .
  591.   -- .  DOUBLY_LINKED_LIST.GOTO_ELEMENT                     .  SPEC
  592.   -- .                                                      .
  593.   -- ........................................................
  594.   procedure Goto_Element (ID    : in out LIST_ID;
  595.                           Index : in ELEMENT_POSITION);
  596.   --| Purpose
  597.   --| Set the current element of the list to be the Nth (INDEX)
  598.   --| element.
  599.   --|
  600.   --| Exceptions
  601.   --|   INVALID_INDEX
  602.   --|   LIST_IS_EMPTY
  603.   --|
  604.   --| Notes (none)
  605.    
  606.   -- ........................................................
  607.   -- .                                                      .
  608.   -- .  DOUBLY_LINKED_LIST.CURRENT_INDEX                    .  SPEC
  609.   -- .                                                      .
  610.   -- ........................................................
  611.   function Current_Index (ID : in LIST_ID) return ELEMENT_POSITION;
  612.   --| Purpose
  613.   --| Return the number of the current element.
  614.   --|
  615.   --| Exceptions
  616.   --|   LIST_IS_EMPTY
  617.   --|
  618.   --| Notes (none)
  619.    
  620.   -- ........................................................
  621.   -- .                                                      .
  622.   -- .  DOUBLY_LINKED_LIST.LAST_INDEX                       .  SPEC
  623.   -- .                                                      .
  624.   -- ........................................................
  625.   function Last_Index (ID : in LIST_ID) return ELEMENT_POSITION;
  626.   --| Purpose
  627.   --| Return the number of the last element.
  628.   --|
  629.   --| Exceptions
  630.   --|   LIST_IS_EMPTY
  631.   --|
  632.   --| Notes (none)
  633.    
  634.   -- ........................................................
  635.   -- .                                                      .
  636.   -- .  DOUBLY_LINKED_LIST.ADVANCE                          .  SPEC
  637.   -- .                                                      .
  638.   -- ........................................................
  639.   procedure Advance (ID : in out LIST_ID);
  640.   --| Purpose
  641.   --| Advance, setting the current element to be the next
  642.   --| element.
  643.   --|
  644.   --| Exceptions
  645.   --|   ADVANCE_PAST_END_OF_LIST
  646.   --|   LIST_IS_EMPTY
  647.   --|
  648.   --| Notes (none)
  649.    
  650.   -- ........................................................
  651.   -- .                                                      .
  652.   -- .  DOUBLY_LINKED_LIST.BACKUP                           .  SPEC
  653.   -- .                                                      .
  654.   -- ........................................................
  655.   procedure Backup (ID : in out LIST_ID);
  656.   --| Purpose
  657.   --| Backup, setting the current element to be the previous
  658.   --| element.
  659.   --|
  660.   --| Exceptions
  661.   --|   BACKUP_BEFORE_BEGINNING_OF_LIST
  662.   --|   LIST_IS_EMPTY
  663.   --|
  664.   --| Notes (none)
  665.    
  666.   -- ........................................................
  667.   -- .                                                      .
  668.   -- .  DOUBLY_LINKED_LIST.IS_EMPTY                         .  SPEC
  669.   -- .                                                      .
  670.   -- ........................................................
  671.   function Is_Empty (ID : in LIST_ID) return BOOLEAN;
  672.   --| Purpose
  673.   --| Return TRUE if the list is empty.
  674.   --|
  675.   --| Exceptions (none)
  676.   --| Notes (none)
  677.    
  678.   -- ........................................................
  679.   -- .                                                      .
  680.   -- .  DOUBLY_LINKED_LIST.IS_END                           .  SPEC
  681.   -- .                                                      .
  682.   -- ........................................................
  683.   function Is_End (ID : in LIST_ID) return BOOLEAN;
  684.   --| Purpose
  685.   --| Return TRUE if the end of the list has been passed.
  686.   --|
  687.   --| Exceptions (none)
  688.   --| Notes (none)
  689.    
  690.   -- ........................................................
  691.   -- .                                                      .
  692.   -- .  DOUBLY_LINKED_LIST.IS_FIRST                         .  SPEC
  693.   -- .                                                      .
  694.   -- ........................................................
  695.   function Is_First (ID : in LIST_ID) return BOOLEAN;
  696.   --| Purpose
  697.   --| Return TRUE if the current element is the first element.
  698.   --|
  699.   --| Exceptions (none)
  700.   --| Notes (none)
  701.    
  702.   -- ........................................................
  703.   -- .                                                      .
  704.   -- .  DOUBLY_LINKED_LIST.APPEND_ELEMENT                   .  SPEC
  705.   -- .                                                      .
  706.   -- ........................................................
  707.   procedure Append_Element (ID      : in out LIST_ID;
  708.                             Element : ELEMENT_OBJECT);
  709.   --| Purpose
  710.   --| Append an element after the current element; set the current
  711.   --| element to this new element.
  712.   --|
  713.   --| Exceptions
  714.   --|   DYNAMIC_MEMORY_ALLOCATION_PROBLEM
  715.   --|
  716.   --| Notes (none)
  717.    
  718.   -- ........................................................
  719.   -- .                                                      .
  720.   -- .  DOUBLY_LINKED_LIST.INSERT_ELEMENT                   .  SPEC
  721.   -- .                                                      .
  722.   -- ........................................................
  723.   procedure Insert_Element (ID      : in out LIST_ID;
  724.                             Element : ELEMENT_OBJECT);
  725.   --| Purpose
  726.   --| Insert an element before the current element; the current
  727.   --| element remains unchanged.
  728.   --|
  729.   --| Exceptions
  730.   --|   DYNAMIC_MEMORY_ALLOCATION_PROBLEM
  731.   --|
  732.   --| Notes (none)
  733.    
  734.   -- ........................................................
  735.   -- .                                                      .
  736.   -- .  DOUBLY_LINKED_LIST.DELETE_ELEMENT                   .  SPEC
  737.   -- .                                                      .
  738.   -- ........................................................
  739.   procedure Delete_Element (ID : in out LIST_ID);
  740.   --| Purpose
  741.   --| Delete the current element; the current element becomes the
  742.   --| element following the current element.
  743.   --|
  744.   --| Exceptions
  745.   --|   ADVANCE_PAST_END_OF_LIST
  746.   --|   LIST_IS_EMPTY
  747.   --|
  748.   --| Notes (none)
  749.    
  750. private
  751.    type ELEMENT;
  752.    type ELEMENT_POINTER is access ELEMENT;
  753.    type ELEMENT is 
  754.       record
  755.          Content  : ELEMENT_OBJECT;
  756.          Next     : ELEMENT_POINTER;
  757.          Previous : ELEMENT_POINTER;
  758.       end record;
  759.    type LIST_ID is 
  760.       record
  761.          First              : ELEMENT_POINTER  := null;
  762.                                 -- first element
  763.          Last               : ELEMENT_POINTER  := null;
  764.                                 -- last element
  765.          Current            : ELEMENT_POINTER  := null;
  766.                                 -- current element
  767.          Free               : ELEMENT_POINTER  := null;
  768.                                 -- free element list
  769.          Number_of_Elements : ELEMENT_POSITION := 0;
  770.                                 -- number of elements
  771.          Current_Index      : ELEMENT_POSITION := 0;
  772.                                 -- index of current element
  773.       end record;
  774.  
  775. end Doubly_Linked_List;
  776.  
  777. -- ****************************************************
  778. -- *                                                  *
  779. -- *  TOD_UTILITIES                                   *  SPEC
  780. -- *                                                  *
  781. -- ****************************************************
  782. with Calendar;  -- Predefined (internal representation) TOD package.
  783. package TOD_Utilities is
  784. --| Purpose
  785. --| This package will provide direct conversion from an external
  786. --| time/date string to the internal Ada CALENDAR.TIME representation
  787. --| and vice versa.  Most free format external representations are
  788. --| supported.  Components of an external format include:
  789. --|   Year, Month and Day (as numbers and strings), Hour, Minutes,
  790. --|   and Seconds
  791. --| As long as the external representation can be parsed unambiguously,
  792. --| this package should be able to handle the conversion.  Examples of
  793. --| legal external formats:
  794. --|   7pm Fr March 12, 1982
  795. --|   15 Dec. 84 12:36PM
  796. --|   YESTERDAY 3PM
  797. --|   6/01/83          <-- defaults to 12:00:00AM
  798. --|   3:45AM           <-- defaults to the current date
  799. --|   18:07:35         <-- defaults to the current date
  800. --|   8-26             <-- defaults to 12:00:00AM of the current year
  801. --|   friday           <-- defaults to 12:00:00AM of the current or next
  802. --|                        future Friday
  803. --| Examples of illegal external representations:
  804. --|   2/31/84          <-- February never has a 31st day
  805. --|   12:3605/01/84    <-- too tough to parse (nondeterminstic)
  806. --|   3/8423:00:00     <-- too tough to parse (nondeterminstic)
  807. --|   3:54:29AMTues    <-- too tough to parse (nondeterminstic)
  808. --|   Nov 1983         <-- must always include day number in the date
  809. --|   Sun 8/3/84       <-- 8/3/84 was a Friday
  810. --|
  811. --| Optional periods may be placed after ABBREVIATED day/month names.
  812. --|
  813. --| All external formats are converted to upper case, so there are no
  814. --| problems with specifying mixed and/or lower case input.  All
  815. --| results are returned in upper case by default (which can be overridden
  816. --| by specifying lower case or mixed case).
  817. --|
  818. --| Special external formats: TODAY, TOMORROW, YESTERDAY, NOW
  819. --| TODAY is equivalent to 12AM of the current date.  TOMORROW and
  820. --| YESTERDAY are equivalent to the next/previous date.  NOW is
  821. --| equivalent to calling the function CALENDAR.CLOCK.
  822. --|
  823. --| Defaults:
  824. --|   If the year is omitted, it defaults to the current year.  If the
  825. --|   time is omitted, it defaults to 12:00:00AM.  If the day name and no
  826. --|   date is specified, the current or next future date is assumed.  If
  827. --|   only the time is specified, the current date is assumed.  If the
  828. --|   minutes and/or seconds are not specified in the time, they default
  829. --|   to zero.  If the year is given in short format (1 or 2 digits) then
  830. --|   it defaults to the current century.
  831. --|
  832. --| BNF for the external representation:
  833. --|   {<special_format> [<time>] |
  834. --|    [<time>] <special_format> |
  835. --|    <day_string> &|* <date> &|* <time>}
  836. --|
  837. --|   <special_format> ::= {TODAY | TOMORROW | YESTERDAY | NOW}
  838. --|
  839. --|   <day_string> ::= SU|NDAY, MO|NDAY, ..., SA|TURDAY
  840. --|
  841. --|   <date> ::= {<month_number><sep1><day_number>[<sep1><year_number>] |
  842. --|               <month_name><sep2><day_number>[<sep2><year_number>] |
  843. --|               <day_number><sep2><month_name>[<sep2><year_number>] |
  844. --|               <full_year_number><sep2><month_name><sep2><day_number> |
  845. --|               <full_year_number><sep2><day_number><sep2><month_name>}
  846. --|
  847. --|   <time> ::= {<hour>':'<minutes>[':'<seconds>][<AM_PM>] |
  848. --|               <AMPM_hour><AM_PM>}
  849. --|
  850. --|   <month_number> ::= 1 .. 12
  851. --|   <month_name> ::= JAN|UARY, FEB|RUARY, ..., DEC|EMBER
  852. --|   <day_number> ::= 1 .. 31
  853. --|   <year_number> ::= {<short_year_number> | <full_year_number>}
  854. --|   <short_year_number> ::= [0]0 .. 99    <-- for century 2000
  855. --|                           [0]1 .. 99    <-- for century 2100
  856. --|   <full_year_number> ::= 1901 .. 2099
  857. --|   <sep1> ::= {'-'|'/'}
  858. --|   <sep2> ::= {<sep1> | {' ' | ','} ...}
  859. --|
  860. --|   <hour> ::= [0]0 .. 24
  861. --|   <AMPM_hour> ::= [0]1 .. 12
  862. --|   <minutes> ::= 00 .. 59
  863. --|   <seconds> ::= 00 .. 59
  864. --|   <AM_PM> ::= {"AM" | "PM"}
  865. --|
  866. --|   Notes on the BNF above:
  867. --|     Items in angle brackets must be separated by at least one
  868. --|     blank and/or comma when they appear with exactly one space
  869. --|     between them.
  870. --|
  871. --|     However, items in angle brackets which are not separated by
  872. --|     exactly one blank have a more rigid syntax, and must be followed
  873. --|     precisely as specified in the BNF.
  874. --|
  875. --|     Some characters/strings are enclosed in quotes to emphasize that
  876. --|     they are explicit, and not metasymbols.  When specifying an
  877. --|     external TOD_String, do NOT include the quotes.
  878. --|
  879. --|     The AM/PM indicator may be left off the time if at least the
  880. --|     hours and minutes are specified.  If only the hour is specified,
  881. --|     it must be in the range 01 .. 12 and must have the AM/PM
  882. --|     indicator following it.  If the AM/PM indicator is left off a
  883. --|     time format, AM is assumed unless the hour is in the range
  884. --|     13 .. 23.  If the AM/PM indicator is included, the hour must
  885. --|     be in the range 01 .. 12.
  886. --|
  887. --|     Notation:
  888. --|       {...|...|...}    -- Select exactly one alternative.
  889. --|       [...]            -- Optional.
  890. --|       &|               -- Select one or the other or both,
  891. --|       &|*              -- Same as &| with the extension of selecting
  892. --|                           the items in any order.
  893. --|       ' '              -- Encloses a character literal.
  894. --|       " "              -- Encloses a string.
  895. --|       < >              -- Encloses a non-terminal symbol.
  896. --|       ...              -- Denotes a repeatable field.
  897. --|       |                -- Separates alternatives and denotes legal
  898. --|                        -- abbreviations.
  899. --|
  900. --| Initialization Exceptions (none)
  901. --| Notes (none)
  902. --|
  903. --| Modifications
  904. --| Author:  Geoff Mendal, Stanford University
  905.  
  906.   External_TOD_Representation_Length : constant POSITIVE := 38;
  907.   subtype EXTERNAL_TOD_REPRESENTATION_TYPE is STRING (
  908.     1 .. External_TOD_Representation_Length);
  909.   -- This type should be used to retrieve an external TOD
  910.   -- representation from the CALENDAR.TIME representation.
  911.  
  912.   type TYPE_SET is (UPPER_CASE, lower_case, Mixed_Case);
  913.   -- This type should be used to specify the type set of an
  914.   -- external representation returned by the internal-to-external
  915.   -- function below.
  916.  
  917.   -- ..................................................
  918.   -- .                                                .
  919.   -- .  TOD_UTILITIES.VERSION                         .  SPEC
  920.   -- .                                                .
  921.   -- ..................................................
  922.   function Version return STRING;
  923.   --| Purpose
  924.   --| Returns the version number of this package.
  925.   --|
  926.   --| Exceptions (none)
  927.   --| Notes (none)
  928.  
  929.   -- ....................................................
  930.   -- .                                                  .
  931.   -- .  TOD_UTILITIES.CONVERT                           .  SPEC
  932.   -- .                                                  .
  933.   -- ....................................................
  934.   function Convert (
  935.     TOD_Value       : in CALENDAR.TIME;
  936.     Default_Setting : in TYPE_SET := UPPER_CASE)
  937.     return EXTERNAL_TOD_REPRESENTATION_TYPE;
  938.   --| Purpose
  939.   --| The following function will take the CALENDAR.TIME representation
  940.   --| and return an external representation. The external representation
  941.   --| has the following format:
  942.   --|   Columns  1 ..  9 : Day as a string
  943.   --|   Columns 11 .. 12 : Day as a number
  944.   --|   Columns 14 .. 22 : Month as a string
  945.   --|   Columns 24 .. 27 : year number
  946.   --|   Columns 29 .. 38 : time in AM/PM format
  947.   --|   All unused columns are blank
  948.   --|
  949.   --|  Example string returned:
  950.   --|    "THURSDAY  09 AUGUST    1984 05:19:05PM"
  951.   --|
  952.   --| Exceptions (none)
  953.   --| Notes (none)
  954.  
  955.   -- ....................................................
  956.   -- .                                                  .
  957.   -- .  TOD_UTILITIES.NOW                               .  SPEC
  958.   -- .                                                  .
  959.   -- ....................................................
  960.   function Now (Default_Setting : in TYPE_SET := UPPER_CASE)
  961.     return EXTERNAL_TOD_REPRESENTATION_TYPE;
  962.   --| Purpose
  963.   --| This function is a convenience, equivalent to calling
  964.   --| the above Convert function with an argument of
  965.   --| CALENDAR.CLOCK.  The current time and date are
  966.   --| returned as specified for Convert above.
  967.   --|
  968.   --| Exceptions (none)
  969.   --| Notes
  970.   --|    Same as Convert(Calendar.Clock)
  971.  
  972.   -- ....................................................
  973.   -- .                                                  .
  974.   -- .  TOD_UTILITIES.CONVERT                           .  SPEC
  975.   -- .                                                  .
  976.   -- ....................................................
  977.   function Convert (TOD_String : in STRING) return CALENDAR.TIME;
  978.   --| Purpose
  979.   --| This function will take an external TOD representation
  980.   --| and return the CALENDAR.TIME representation.  The external
  981.   --| representation can be any STRING object that conforms to
  982.   --| the BNF given above.
  983.   --|
  984.   --| Exceptions (see below)
  985.   --| Notes (none)
  986.  
  987.   Duplication_Error,                          -- "5/25/61 May 25 1961"
  988.   Date_Error,                                 -- "2/31/75"
  989.   Month_Number_Error,                         -- "13/1/1960"
  990.   Year_Error,                                 -- "1/1/1900"
  991.   Day_Number_Error,                           -- "1/32/1984"
  992.   Day_Date_Error,                             -- "Sunday 8/3/84"
  993.   Month_Missing_Error,                        -- "1961 25"
  994.   Day_Number_Missing_Error,                   -- "1961 May"
  995.   Hour_Error,                                 -- "25:00:00"
  996.   Minute_Error,                               -- "23:61:00"
  997.   Second_Error,                               -- "23:59:60"
  998.   Time_String_Error,                          -- "1:05:05:PM"
  999.   Abbreviation_Error,                         -- "Sept.emb. 5"
  1000.   External_Representation_Error : exception;  -- "blah blah blah"
  1001.   -- These exceptions will be raised if the input to the
  1002.   -- above function cannot be parsed unambiguously.  Also, this function
  1003.   -- traps CALENDAR.TIME_ERROR and instead raises the exception
  1004.   -- Date_Error below in its place.
  1005.  
  1006. end TOD_Utilities;
  1007.  
  1008.  
  1009.  
  1010.